package com.abner.design.patterns.factory.simplefactory.normal;

import com.abner.design.patterns.factory.simplefactory.pizza.CheesePizza;
import com.abner.design.patterns.factory.simplefactory.pizza.GreekPizza;
import com.abner.design.patterns.factory.simplefactory.pizza.PepperPizza;
import com.abner.design.patterns.factory.simplefactory.pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;



/**
 * 披萨店(正常写法)
 * 	 分析: 当拥有多个披萨店时,新增一个披萨种类时,各个披萨店都需要更改
 * 	 更改: 把披萨封装到一个披萨工厂类中,新增一个披萨种类时,只需修改披萨工厂代码(简单工厂模式)
 * @author abner
 */
public class OrderPizza {

	public OrderPizza() {
		Pizza pizza = null;
		/**
		 * 披萨类型
		 */
		String orderType;
		do {
			orderType = getType();
			if ("greek".equals(orderType)) {
				pizza = new GreekPizza();
				pizza.setName("希腊披萨");
			} else if ("cheese".equals(orderType)) {
				pizza = new CheesePizza();
				pizza.setName("奶酪披萨");
			} else if ("pepper".equals(orderType)) {
				pizza = new PepperPizza();
				pizza.setName("胡椒披萨");
			} else {
				break;
			}
			/**
			 * 披萨制作过程
			 */
			pizza.prepare();
			pizza.bake();
			pizza.cut();
			pizza.box();

		} while (true);
	}

	/**
	 * 获取控制台输入的披萨
	 * @return
	 */
	private String getType() {
		try {
			BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
			System.out.println("input pizza type:");
			String str = in.readLine();
			return str;
		} catch (IOException e) {
			e.printStackTrace();
			return "";
		}
	}

}
